package com.ks.community.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ks.community.entity.Post;
import com.ks.community.entity.vo.PostVo;
import com.ks.community.mapper.PostMapper;
import com.ks.community.service.PostService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dCoder
 * @since 2022-04-07
 */
@Service
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements PostService {


    @Override
    public void addOne(PostVo postVo) {
        Post post = new Post();
        BeanUtils.copyProperties(postVo,post);
        post.setInsertTime(new Date());
        baseMapper.insert(post);
    }

    @Override
    public List<Post> SelectAll(){
        return baseMapper.selectList(null);
    }

    @Override
    public List<Post> SelectById(String upId) {
        return baseMapper.selectList(new QueryWrapper<Post>().eq("uploader_id",upId));
    }
}
